#include <errno.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>

const size_t cache_size = 1024;

int main() {
  char line[cache_size];
  std::fstream datain;
  datain.open("datain.txt", std::ios::in);
  if (!datain) {
    std::cout << "open datain.txt: " << strerror(errno) << std::endl;
    return 1;
  }

  std::fstream dataout;
  dataout.open("dataout.txt", std::ios::out | std::ios::trunc);
  if (!datain) {
    std::cout << "open dataout.txt: " << strerror(errno) << std::endl;
    return 1;
  }

  std::streamsize n;
  while (!datain.eof()) {
    datain.read(line, cache_size);
    n = datain.gcount();
    for (int i = 0; i < n; i++) {
      line[i] = toupper(line[i]);
    }

    dataout.write(line, n);
  }
  datain.close();
  dataout.close();
}
